package com.zd.commodity.productMng.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.zd.commodity.dao.impl.BaseDao;
import com.zd.commodity.productMng.dao.IProductPriceDao;
import com.zd.commodity.productMng.entity.ProductPrice;

@Repository("productPriceDao")
public class ProductPriceDaoImpl extends BaseDao<ProductPrice> implements IProductPriceDao {

	@Resource(name = "sessionFactory")
	public void setSuperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
	@Override
	public DetachedCriteria getDetachedCriteria(ProductPrice t1,ProductPrice t2,Object params){
		DetachedCriteria dc=DetachedCriteria.forClass(ProductPrice.class);
		if(t1!=null){
			if(t1.getProduct()!=null){
				dc.createAlias("product", "p");
				if(t1.getProduct().getId()!=null && !t1.getProduct().getId().equals("")){
					dc.add(Restrictions.eq("p.id", t1.getProduct().getId()));
				}
			}
		}
		return dc;
	}
	
	public List<ProductPrice> findByProductId(Long productId){
		return getHibernateTemplate().find("from ProductPrice where product_id="+productId);
	}
}
